package com.eastedu.report.common.model.parameter;

import com.eastedu.common.enums.DateCodeType;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Builder;
import lombok.Getter;

import java.util.Objects;

/**
 * 报告生成参数
 *
 * @author superman
 */
@Getter
@Builder
public class ReportGenerateParameter {
    private final Long schoolGroupId;
    private final String schoolGuid;
    private final String section;

    /**
     * 以下参数不参与去重
     */
    private final DateCodeType codeType;
    private final Integer dateCode;
    private final String schoolName;
    private final String sectionName;
    @Schema(description = "是否开启调试模式")
    private boolean debug;

    /**
     * Gets code type.
     *
     * @return the code type
     */
    public DateCodeType getCodeType() {
        if (Objects.isNull(this.codeType)) {
            return DateCodeType.MONTH;
        }
        return codeType;
    }

    /**
     * Gets date code.
     *
     * @return the date code
     */
    public Integer getDateCode() {
        if (Objects.isNull(this.dateCode)) {
            return getCodeType().getLast();
        }
        return dateCode;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        ReportGenerateParameter that = (ReportGenerateParameter) o;

        if (!schoolGroupId.equals(that.schoolGroupId)) {
            return false;
        }
        if (!schoolGuid.equals(that.schoolGuid)) {
            return false;
        }
        return section.equals(that.section);
    }

    @Override
    public int hashCode() {
        int result = schoolGroupId.hashCode();
        result = 31 * result + schoolGuid.hashCode();
        result = 31 * result + section.hashCode();
        return result;
    }
}
